package app.mvc.controller.editor
{
	import app.consts.CommandType;
	import app.interfaces.IEditorCommand;
	import app.mvc.AppFacade;
	import app.mvc.Notifications;
	import app.mvc.model.VO.UIObjectVO;
	import app.mvc.model.proxys.EditorDataProxy;
	import app.mvc.view.components.uiControls.UIObject;
	import app.mvc.view.mediators.ObjectsViewMediator;
	
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	public class MoveObjectCommand extends EditorBaseCommand implements ICommand, IEditorCommand
	{
		public static var continueMoveX:int=0;
		public static var continueMoveY:int=0;
		public function MoveObjectCommand()
		{
			super();
		}		
		
		override public function redo():void
		{
			super.redo();
			execute(_notification);
		}
		
		override public function undo():void
		{
			super.undo();
			var obj:Object=  _notification.getBody();
			var selectedObjects:Array = obj.selectedObjects;
			var changeX:int = -obj.changeX;
			var changeY:int = -obj.changeY;
			AppFacade.getInstance().sendNotification(Notifications.CMD_TO_MOVE_OBJECTS,{selectedObjects:selectedObjects,changeX:changeX,changeY:changeY},CommandType.UNDO);			
		}
		
		override public function execute(notification:INotification):void
		{
			// TODO Auto Generated method stub
			super.execute(notification);
			var obj:Object=  notification.getBody();
			var selectedObjects:Array = obj.selectedObjects;
			var changeX:int = obj.changeX;
			var changeY:int = obj.changeY;
			
			var uid:String = "";
			var objectsViewM:ObjectsViewMediator =  AppFacade.getInstance().retrieveMediator(ObjectsViewMediator.NAME) as ObjectsViewMediator;
			var data:UIObjectVO = null;
			
			var len:int = selectedObjects.length;
			if(len>0)
			{
				EditorDataProxy.getInstance().moveObjects(selectedObjects,changeX,changeY);
				AppFacade.getInstance().sendNotification(Notifications.TO_MOVE_OBJECTS,{selectedObjects:selectedObjects,changeX:changeX,changeY:changeY});
			}
		}
		
	}
}